﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Mvvm
{
    public class MvvmCommand : ICommand
    {
        private readonly Action<object> executeAction;
        private readonly Func<object, bool> canExecute;
        private bool canExecuteCache;
        public event EventHandler CanExecuteChanged;

        public MvvmCommand(Action<object> executeAction, Func<object, bool> canExecute)
        {
            this.executeAction = executeAction;
            this.canExecute = canExecute;
        }

        public bool CanExecuteCache
        {
            get 
            { 
                return canExecuteCache; 
            }
            
            set 
            { 
                canExecuteCache = value;

                if (CanExecuteChanged != null)
                {
                    CanExecuteChanged(this, new EventArgs());
                }
            }
        }

        public bool CanExecute(object parameter)
        {
            return canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            executeAction(parameter);
        }
    }
}
